<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list .aui-list-item-media {
            width: 3rem;
        }
        p{color: black;line-height: 22px;}
    </style>
</head>
<body>
    <section class="aui-content aui-margin-t-10" id="daily-list">

    </section>

</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
var toast = new auiToast();
apiready = function(){
     $api.setStorage("daily_index", 0);
     load();
     //上拉翻页
     api.addEventListener({
         name : 'scrolltobottom'
     }, function(ret, err) {
         $api.setStorage("daily_index", $api.getStorage("daily_index") - 0 + 1);
         load();
     });
 }

//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("daily_index");
     var username = $api.getStorage("username");
     var url = ServeUrl + "m=Daily&a=myDailyList&pageIndex=" + index + "&pageCount=15&username="+username;
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
           toast.success({
              title:"已加载所有日报",
              duration:2000
          });
             api.hideProgress();
         }
     });
 }

//字符串拼接
 function dealWithHtml(data, first, index) {
    //alert(JSON.stringify(data));
     var html = '';
     for (var i = 0; i < data.data.length; i++) {
          if(data.data[i].user_img){
             user_img = ServeIp+'include/data/headImg/'+data.data[i].user_img;
          }else {
             user_img = '../image/demo1.png';
          }
          html+='<div class="aui-card-list">'
          html+='<div class="aui-card-list-header aui-card-list-user">'
          html+='<div class="aui-card-list-user-avatar">'
          html+='<img src="'+user_img+'" class="aui-margin-r-10" style="width:2rem;border-radius:4px;" />'
          html+='</div>'
          html+='<div class="aui-card-list-user-name">'
          html+='<div>'+data.data[i].cn_name+'</div>'
          html+='<div class="aui-label aui-label-primary aui-label-outlined">'+data.data[i].daily_type+'</div>'
          html+='</div>'
          html+='<div class="aui-card-list-user-info">'+data.data[i].createtime+'</div>'
          html+='</div>'
          html+='<div class="aui-card-list-content aui-list aui-media-list aui-list-noborder aui-padded-t-0">'
          html+='<div class="aui-list-item aui-list-item-middle aui-padded-r-15">'
          html+='<div class="aui-media-list-item-inner ">'
          html+='<div class="aui-list-item-inner aui-padded-l-10">'+data.data[i].daily_content+'</div>'
          html+='</div>'
          html+='</div>'
          html+='</div>'
          html+='<div class="aui-card-list-footer aui-border-b" style="padding-left:1.5rem;padding-right:1.5rem;">'
          html+='<div><i class="aui-iconfont aui-icon-laud aui-margin-r-5"></i>赞</div>'
          html+='<div><i class="aui-iconfont aui-icon-comment aui-margin-r-5"></i>评论</div>'
          html+='</div>'



          html += '<section class="aui-content-padded aui-padded-b-10">'
          for (var j = 0; j < data.data[i].comment.length; j++) {
              html += '<p onclick="reply('+"'"+data.data[i].comment[j].parent.createname+"',"+data.data[i].comment[j].parent.id+','+data.data[i].id+')"><a>'+data.data[i].comment[j].parent.createname+'</a>&nbsp;:&nbsp;'+data.data[i].comment[j].parent.comment+'</p>'
              for (var k = 0; k < data.data[i].comment[j].child.length; k++) {
                  html += '<p onclick="reply('+"'"+data.data[i].comment[j].child[k].parent.createname+"',"+data.data[i].comment[j].parent.id+','+data.data[i].id+')"><a>'+data.data[i].comment[j].child[k].parent.createname+'</a>&nbsp;回复&nbsp;<a>'+data.data[i].comment[j].child[k].parent.receiveman+'</a>:&nbsp;'+data.data[i].comment[j].child[k].parent.comment+'</p>'
              }
          }
          html += '</section>'
          html+='</div>'
     }
    $("#daily-list").append(html);
    api.hideProgress();

 }

 function reply(){
    alert(11);
 }
</script>
</html>
